#pragma once

#include<iostream>
#include<string>
#include<cstdio>
#include<functional>

class CalTask
{
    using func_t = std::function<int(int,int,char)>;

    public:
        CalTask() {}
        CalTask(int x,int y,char op,func_t func):_x(x),_y(y),_op(op),_calback(func) {}

        std::string operator()()
        {
            int res = _calback(_x,_y,_op);
            char buffer[1024];
            snprintf(buffer,sizeof buffer,"%d %c %d = %d\n",_x,_op,_y,res);
            return buffer;
        }

        std::string toTaskstring()
        {
            char buffer[1024];
            snprintf(buffer,sizeof buffer,"%d %c %d = ?\n",_x,_op,_y);
            return buffer;
        }

    private:
        int _x;
        int _y;
        char _op;
        func_t _calback;
};

const std::string oper = "+-*/%";

int mymath(int x,int y,char op)
{
    int ret=0;
    switch(op)
    {
        case '+':ret=x+y;break;
        case '-':ret=x-y;break;
        case '*':ret=x*y;break;
        case '/':
        {
            if(y==0)
            {
                std::cout<<"div zero!"<<std::endl;
                ret = -1;
            }
            else
                ret = x/y;
            break;
        }
        case '%':
        {

            if(y==0)
            {
                std::cout<<"mod zero!"<<std::endl;
                ret = -1;
            }
            else
                ret = x%y;
            break;
        }
        default:break;
    }

    return ret;
}
